package auth

import (
	"grpc.getaway.adminspro.padmins.com/internal/api/module/admin/container"
	"grpc.getaway.adminspro.padmins.com/internal/api/utils/rpc"
	pbAuthorizationAdmin "grpc.getaway.adminspro.padmins.com/pkg/proto/authorizationAdmin"
)

func GetInfo(c *container.Context) (interface{}, error) {
	req := &pbAuthorizationAdmin.GetResourceReq{
		ResourceIds: c.Auth.Data.ResourceIds,
	}

	getResourceReq, e := rpc.GetAuthorizationAdminClient().GetResource(c.GetContext(), req)
	if e != nil {
		return nil, e
	}

	//Resources := make([]proto.Message, len(getResourceReq.Resources))
	//for i, Resource := range getResourceReq.Resources {
	//	Resources[i] = Resource
	//}
	//rules := rpc.ProtoMessageToList(Resources)
	rules := rpc.ProtoMessageToMap(getResourceReq)["Resources"]
	Data := rpc.ProtoMessageToMap(c.Auth.Data)

	return map[string]interface{}{
		"auth":  Data["admin"],
		"roles": Data["roles"],
		"rules": rules,
	}, nil
}
